import { Vechile, Car, Bus } from "../extendsdemo/demo1";

// 泛型接口 泛型约束 多态的应用
class Customer{

  // 泛型约束
  public rentVechile<T extends object>(myVechileArray: Array<T>) {
    let total: number = 0;
    myVechileArray.forEach((vechile) => {
      // 保障方法,所以使用类型断言
      total += (vechile as any).calculateRent();
    });
    return total;
  }
}

// 改造成接口


//一个父类数组对象变量的每一个元素都可以接受任何一个该父类的子类对象
let vechileArray = new Array<Vechile>();

vechileArray.push(new Bus("大巴", "京3A556", 3, 50000, 67));
vechileArray.push(new Car("大卡车", "京7A556", 2, 60000, "兰博基尼"));
let cust = new Customer();
let lasttotal = cust.rentVechile<Vechile>(vechileArray);
console.log("lasttotal:", lasttotal);



// let strs = ['aaa','bbb']
// let lasttotal2 = cust.rentVechile<string>(strs);//! 使用字符串 泛型约束之后不能使用
// console.log("lasttotal:", lasttotal2);


export {};
